package com.bwsoft.api.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Map;
import java.util.UUID;

import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.bwsoft.api.pojo.ResponsePojo;
import com.bwsoft.api.util.Constant;
import com.bwsoft.util.Base64Util;
import com.bwsoft.util.DesUtil;
import com.bwsoft.util.ValidatorUtil;

public class MethodAction extends ApiBaseAction<MethodAction> {
	private static Logger LOG = Logger.getLogger(MethodAction.class);

	private String data;
	
	
	public void jiaMi() throws Exception{
		
		try{
		data=Base64Util.getBase64(DesUtil.encrypt(data, Constant.KEY_DES).getBytes());
		}catch (Exception e) {
			e.printStackTrace();
		}
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(data);
		out.flush();
		out.close();
		
	}
	
	
	public void jieMi() throws Exception, Exception{
		try{
		data=DesUtil.decrypt(Base64Util.getFromBase64(data), Constant.KEY_DES);
	}catch (Exception e) {
		e.printStackTrace();
	}
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(data);
		out.flush();
		out.close();
		
	}
	
	
	
	public void getFile() throws IOException, Exception{
		
		LOG.info("传入参数r="+super.getR());
		if(r==null||r.trim().equals("")){
			responseJson.put("errcode", 1);
			responseJson.put("errmsg", "r值不能为空");
			finishMethod();
			LOG.info("=======================================传入参数r为空，提前结束");
		}
		Map<String, Object> parameMap= reflexParameters();
		
		Integer fileid=Integer.parseInt( (String) parameMap.get("fileid"));
		
		com.bwsoft.admin.domain.File file= fileDao.findById(fileid);
		
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(file.getPath());
		out.flush();
		out.close();
		
	}


	public String getData() {
		return data;
	}


	public void setData(String data) {
		this.data = data;
	}
	
	

}
